package com.iams.manage.controller;

import com.iams.common.annotation.Log;
import com.iams.common.core.controller.BaseController;
import com.iams.common.core.domain.AjaxResult;
import com.iams.common.core.page.TableDataInfo;
import com.iams.common.enums.BusinessType;
import com.iams.common.utils.SecurityUtils;
import com.iams.common.utils.poi.ExcelUtil;
import com.iams.manage.domain.workflow.DestroyRecord;
import com.iams.manage.domain.workflow.dto.DestroyRecordDTO;
import com.iams.manage.service.IDestroyRecordService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 档案销毁Controller
 * 
 * @author LiuTao
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/manage/ArchiveDestroyRecord")
public class ArchiveDestroyApprovalController extends BaseController
{

    @Autowired
    private IDestroyRecordService destroyRecordService;

    /**
     * 查询档案销毁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:list')")
    @GetMapping("/list")
    @Operation(summary = "查询销毁申请列表", description = "获取销毁申请列表，可根据实体类中的关键字段进行筛选。返回DTO类。")
    public TableDataInfo list(DestroyRecord destroyRecord)
    {
        startPage();
        List<DestroyRecordDTO> list = destroyRecordService.selectDestroyRecordList(destroyRecord);
        return getDataTable(list);
    }

    /**
     * 导出档案销毁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:export')")
    @Log(title = "档案销毁", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出销毁申请列表", description = "获取销毁申请列表，可根据实体类中的关键字段进行筛选。返回DTO类。")
    public void export(HttpServletResponse response, DestroyRecord destroyRecord)
    {
        List<DestroyRecordDTO> list = destroyRecordService.selectDestroyRecordList(destroyRecord);
        ExcelUtil<DestroyRecordDTO> util = new ExcelUtil<DestroyRecordDTO>(DestroyRecordDTO.class);
        util.exportExcel(response, list, "档案销毁数据");
    }

    /**
     * 获取档案销毁详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取销毁记录详细信息", description = "根据id获取销毁申请信息，DTO类，用于修改数据前的获取原数据阶段。")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(destroyRecordService.selectDestroyRecordById(id));
    }

    /**
     * 新增档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:add')")
    @Log(title = "档案销毁", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增销毁记录", description = "新增销毁信息，DTO类。")
    public AjaxResult add(@RequestBody @Valid DestroyRecordDTO destroyRecordDTO)
    {
        return toAjax(destroyRecordService.insertDestroyRecord(destroyRecordDTO));
    }

    /**
     * 修改档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:edit')")
    @Log(title = "档案销毁", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "提交保存修改后的销毁申请", description = "保存修改后的销毁信息，先查询要修改的销毁记录详细信息，后提交DTO类，")
    public AjaxResult edit(@RequestBody @Valid DestroyRecordDTO destroyRecordDTO)
    {
        return toAjax(destroyRecordService.updateDestroyRecord(destroyRecordDTO));
    }

    /**
     * 删除档案销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:ArchiveDestroyRecord:remove')")
    @Log(title = "档案销毁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除销毁记录", description = "根据id删除销毁信息，ids，调用流程相关服务终止实例。")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(destroyRecordService.deleteDestroyRecordByIds(ids));
    }
}
